package typejump.objects;

import java.awt.Color;
import java.awt.Graphics2D;

import typejump.TypeJump;
import typejump.engine.CollisionProps;
import typejump.engine.GameAction;

public abstract class Hotspot extends GameObject {

	private GameObject colwith = null;
	private volatile boolean entered = false;
	
	public Hotspot() {
		setCollision(CollisionProps.T_NONE, CollisionProps.T_PC);
	}
	
	@Override
	public boolean paintEnabled() {
		return TypeJump.getInst().isShowingEditor();
	}

	@Override
	public void paint(Graphics2D g) {
		g.setColor(Color.BLUE);
		g.fillRect(0, 0, iw(), ih());
	}

	@Override
	public void update(double time) {
		if (colwith != null) {
			if (colwith.intersects(this)) {
				if (!entered) {
					onEnter(colwith);
					entered = true;
				}
			} else {
				if (entered) {
					onExit(colwith);
					entered = false;
				}
				colwith = null;
			}
		}
	}

	
	@Override
	public void collide(GameObject other) {
		this.colwith = other;
	}
	
	public abstract void onEnter(GameObject enter);
	public abstract void onExit(GameObject exit);
}
